if(window.location.host == "www.casualcollective.com" && user && typeof ccplus == "undefined") {
	var ccplus = {
		// Initialise 
		init: function() {
			if(!ccplus.support.storage()) {
				alert('CC+ Failure: Your browser does not support localStorage!');
				return false;
			}
			ccplus.hooks.addHooks();
			ccplus.tabs.create();
			ccHistory.hideLoad.apply(ccHistory)
		},
		// Storage
		storage: {
			set: function(key, value) {
				try { // CC uses mootools, no native JSON parsing
					localStorage.setItem(key, JSON.encode(value));
				} catch(e) {
					alert('CC+ Failure: Error while saving');
				}
			},
			get: function(key, defvalue) {
				return (localStorage.getItem(key) ? JSON.decode(localStorage.getItem(key)) : defvalue);
			}
		},
		// Support checks
		support: {
			storage: function() {
				if(typeof localStorage == 'object' && localStorage.setItem)
					return true;
				else
					return false;
			}
		},
		hooks: {
			first: true,
			oldLTick: null,
			oldTick: null,
			oldAjaxLoadHide: null,
			addHooks: function() {
				ccplus.hooks.oldAjaxLoadHide = ccHistory.hideLoad
				ccHistory.hideLoad = function() {
					window.setTimeout(function() {
							if(ccplus.hooks.first) {
								ccplus.hooks.first = false;
								ccplus.scripts.each(function(script) {
									if(script.value) script.events.enable.apply()
								});
							}
							ccplus.scripts.each(function(script) {
								if(script.events.page && script.active) {
									scipt.events.page.apply()
								}
							});
						},
						50
					);
					return ccplus.hooks.oldAjaxLoadHide.apply(ccHistory);
				}
				ccplus.hooks.oldTick = cc.tick;
				cc.tick = function() {
					window.setTimeout(function() {
							ccplus.scripts.each(function(script) {
								if(script.events.update && script.active) {
									script.events.update.apply();
								}
							});
						},
						50
					);
					return ccplus.hooks.oldTick.apply(cc)
				}
				ccplus.hooks.oldLTick = cc.lTick
				cc.lTick = function() {
					window.setTimeout(function() {
							ccplus.scripts.each(function(script) {
								if(script.events.lupdate && element.active) {
									script.events.lupdate.apply()
								}
							});
						},
						50
					);
					return ccplus.hooks.oldLTick.apply(cc)
				}
			}
		},
		// Adding style
		addStyle: function(id, css) {
			// Also adds ID to style tag, so it can be easily removed when needed
			var style = document.createElement('style');
			style.type = 'text/css';
			style.appendChild(document.createTextNode(css));
			style.id = id;
			document.getElementsByTagName('head')[0].appendChild(style);
		},
		// Tabs interface
		tabs: {
			element: false,
			contentelement: false,
			tabs: [],
			tabcontent: [],
			currenttab: null,
			oldTabChange: null,
			create: function() {
				if(ccplus.tabs.element) return false;
				var tabsElement = document.createElement('div');
					tabsElement.id = 'CCplusMenu';
				document.getElementById('sidebar').insertBefore(tabsElement, document.getElementById('sb-twitter'));
				ccplus.tabs.element = tabsElement;
				
				var tabcontents = document.createElement('div')
					tabcontents.id = 'CCPlusModules'
					tabcontents.style.visibility = 'hidden'
				document.getElementById('sb-tabs').insertBefore(tabcontents, document.getElementById('sb-tabs').firstChild)
				ccplus.tabs.contentelement = tabcontents;
				
				ccplus.tabs.oldTabChange = sbTabs.show
				sbTabs.show = function(b,a) {
					if(ccplus.tabs.currenttab !== null) {
						ccplus.tabs.open(ccplus.tabs.currenttab)
					}
					return ccplus.tabs.oldTabChange.apply(sbTabs, new Array(b,a))
				}
				
				ccplus.addStyle('ccplusStyle-Tabs',
						'#CCplusMenu {height: 22px; width: 100%; margin-top: 2px;}'+
						'#CCPlusModules {position: absolute; border-color: #A4CODB #A5C1DB #A5CIDB; border-style: solid; border-width: 1px; height: 400px; width: 298px; background: #FFF; z-index: 9000;}'+
						'.CCPlusModule {height: 398px; overflow: auto; width: 296px; padding:1px;}'+
						'#CCPlusOpen0 span {padding-top: 3px; padding-bottm: 2px; }'
				);
				ccplus.tabs.add(0,'<img id="ccplusLogo" src="http://storage.casualcollective.com/images/global/blank.gif" style="background: url(\'\') no-repeat; height: 17px; width: 16px;" style="cursor: pointer;" title="Open CC+" />');
			},
			add: function(scriptId,tabName) {
				if(ccplus.tabs.tabs[scriptId]) return false;
				var newTab = document.createElement('span');
				newTab.id = 'CCPlusOpen'+scriptId;
				newTab.className = 'usel usel-gray';
				newTab.innerHTML = '<span>'+tabName+'</span>';
				newTab.setAttribute('onclick','ccplus.tabs.open('+scriptId+')');
				ccplus.tabs.element.appendChild(newTab);
				ccplus.tabs.tabs[scriptId] = newTab;
				
				var newTabContent = document.createElement('div')
				newTabContent.className = 'CCPlusModule'
				newTabContent.id = 'CCPlusModule'+scriptId
				newTabContent.innerHTML = ''
				newTabContent.style.visibility = 'hidden'
				newTabContent.style.height = '0px'
				ccplus.tabs.contentelement.appendChild(newTabContent);
				ccplus.tabs.tabcontent[scriptId] = newTabContent;
			},
			open: function(id) {
				if(!ccplus.tabs.tabs[id] || !ccplus.tabs.tabcontent[id]) return false;
				if(ccplus.tabs.currenttab === null) {
					ccplus.tabs.tabcontent[id].style.height = '398px'
					ccplus.tabs.tabcontent[id].style.visibility = 'visible'
					ccplus.tabs.contentelement.style.visibility = 'visible'
					ccplus.tabs.tabs[id].className = 'usel usel-grayon'
					ccplus.tabs.currenttab = id
				} else if (ccplus.tabs.currenttab === id) {
					ccplus.tabs.tabcontent[id].style.height = '0px'
					ccplus.tabs.tabcontent[id].style.visibility = 'hidden'
					ccplus.tabs.contentelement.style.visibility = 'hidden'
					ccplus.tabs.tabs[id].className = 'usel usel-gray'
					ccplus.tabs.currenttab = null
				} else {
					ccplus.tabs.tabcontent[ccplus.tabs.currenttab].style.height = '0px'
					ccplus.tabs.tabcontent[ccplus.tabs.currenttab].style.visibility = 'hidden'
					ccplus.tabs.tabs[ccplus.tabs.currenttab].className = 'usel usel-gray'
					ccplus.tabs.tabcontent[id].style.height = '398px'
					ccplus.tabs.tabcontent[id].style.visibility = 'visible'
					ccplus.tabs.tabs[id].className = 'usel usel-grayon'
				}
			}
		},
		// Scripts
		scripts: []
	}
	ccplus.scripts[0] = {
		name: 'Settings Manager',
		desc: 'For editing settings',
		value: true,
		active: false,
		events: {
			enable: function() {
				ccplus.scripts[0].active = true;
				//alert('Enabling settings manager.')
				if(document.getElementById('ccplusStyle-Settings')) return false;
				ccplus.addStyle('ccplusStyle-Settings',
						'#CCplusConfig .cba-off, #CCplusConfig .cba-on { width: 593px; margin-bottom: 1px; }'+
						'#CCplusConfig .cba { width: 593px; margin-bottom: 1px; padding-left: 0px; }'+
						'#CCplusConfig input[type="text"]{ font-size 12px; margin: 2px 0px; padding: 0px; width: 100px; display: block; float: left;}'+
						'#CCplusConfig label {font-size: 12px; margin: 4px 8px 2px 0px; padding: 0px; width: 100px; display:block; float:left;}'+
						'#CCplusConfig select {font-size: 9px;} #CCplusConfig select option {font-size: 11px;}'+
						'#CCplusConfig .CCplusScriptSettings {border-top: 1px solid #A5C1DB; padding-top: 5px; clear: both;}'+
						'.ccp-featureinfo {font-size: 90%; font-style: italic;}'
				)
			},
			disable: function() { return false; }	// Disable me? NEVER!
		}
	}

	ccplus.init()
}